﻿<%@ Page Language="C#" MasterPageFile="~/Crm/Crm2.master" AutoEventWireup="true" CodeFile="Dictionary.aspx.cs" Inherits="Crm_Dictionary" %>

<asp:Content ID="Content1" ContentPlaceHolderID="head" runat="Server">  
    <style type="text/css">
        a.nav { color: #fff; }
        .none { display: none; }
    </style>   
        <script type="text/javascript">
        $(document).ready(function()
        {
            var selobj = null;
            var selobjcolor = null;
            //d = this.style.backgroundColor; this.style.backgroundColor = '#D1F880';
            $(".trnei,.lupai").each(function()
            {

                $(this).click(function()
                {
                    try
                    {
                        selobj.css("background-color", selobjcolor);
                    }
                    catch (ex)
                    {
                    }
                    selobjcolor = $(this).css("background-color");
                    $(this).css("background-color", "#D1F880");
                    selobj = $(this);
                });    
                var curtr = $(this);
                $(this).find(".btnup").click(function()
                {
                    var id = $(curtr).find("td:first span").text();
                    var px = $(curtr).find("td:last").text();
                    var preid = $(curtr).prev("tr").find("td:first span").text();
                    if (!preid)
                    {
                        alert("已经是最顶端了!");
                        return;
                    }
                    var prev = $(curtr).prev("tr");
                    var prepx = $(curtr).prev("tr").find("td:last").text();
                    //alert("当前id:" + id + "上一个排序:" + prepx + "当前排序 " + px + " 上个id " + preid);
                    $.get("ashx/crmop.ashx?ac=changepx&<%=DateTime.Now %>", {keyid:"id", tbname: "Sys_Dictionary", sid: id, spx: px, toid: preid, topx: prepx }, function(res)
                    {
                        if (res == "ok")
                        {
                            $(curtr).find("td:last").text(prepx);
                            $(curtr).prev("tr").find("td:last").text(px);
                            $(prev).insertAfter($(curtr));
                        }                 
                    });

                });
                $(this).find(".btndown").click(function()
                {
                    var id = $(curtr).find("td:first span").text();
                    var px = $(curtr).find("td:last").text();
                    var preid = $(curtr).next("tr").find("td:first span").text();
                    if (!preid)
                    {
                        alert("已经是最底端了!");
                        return;
                    }
                    var next = $(curtr).next("tr");
                    var prepx = $(curtr).next("tr").find("td:last").text();
                    //alert("当前id:" + id + "上一个排序:" + prepx + "当前排序 " + px + " 上个id " + preid);
                    $.get("ashx/crmop.ashx?ac=changepx&<%=DateTime.Now %>", {keyid:"id", tbname: "Sys_Dictionary", sid: id, spx: px, toid: preid, topx: prepx }, function(res)
                    {
                        if (res == "ok")
                        {
                            $(curtr).find("td:last").text(prepx);
                            $(curtr).next("tr").find("td:last").text(px);
                            $(curtr).insertAfter($(next));
                        }
                    });
                });
            });
        });
    </script>
</asp:Content>
<asp:Content ID="Content2" ContentPlaceHolderID="cbody" runat="Server">
    <div style="padding: 0 5px;">
        <div class="nav" style="border: solid 1px #333;">
            当前位置：<a class="nav" href="Dictionary.aspx">数据字典</a> ＞<%=GetNavLink(int.Parse(pid))%></div>
        <div style="margin-bottom: 5px;">
            <asp:Button ID="btnAddNew" runat="server" Text="新 建" OnClick="btnAddNew_Click" /></div>
        <asp:GridView ID="gvList" runat="server" AutoGenerateColumns="False" 
            DataSourceID="AccessDataSource1" DataKeyNames="id" >
            <Columns>
             <asp:TemplateField HeaderText="编号" >
                    <ItemTemplate>
                    <%#Container.DataItemIndex+1 %>
                    <span style="color:#999;">-<%#Eval("id") %></span>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:BoundField DataField="id" HeaderText="编号" ReadOnly="True" Visible="false" SortExpression="id" InsertVisible="False" />
                <asp:BoundField DataField="pid" HeaderText="父级编号" SortExpression="pid" />
                <asp:BoundField DataField="keytext" SortExpression="keytext" ItemStyle-Width="150px" HeaderText="键文本">
                    <ItemStyle Width="150px"></ItemStyle>
                </asp:BoundField>
                <asp:BoundField DataField="keyvalue" HeaderText="键值" SortExpression="keyvalue" />             
                <asp:TemplateField ShowHeader="False">
                    <ItemTemplate>
                        <a href="Dictionary.aspx?pid=<%#Eval("id") %>&pname=<%#Eval("keytext") %>">进入下一级</a>
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:BoundField DataField="addtime" HeaderText="添加时间" SortExpression="addtime" ReadOnly="True" />
                <asp:BoundField DataField="updatetime" HeaderText="更新时间" SortExpression="updatetime" ReadOnly="true" />
                <asp:BoundField DataField="remark" HeaderText="说明" SortExpression="remark" />
                <asp:CommandField ShowEditButton="True" />
                <asp:TemplateField ShowHeader="False">
                    <ItemTemplate>
                        <asp:LinkButton ID="LinkButton1" OnClientClick="return confirm('注意,请谨慎操作系统字典,确认要删除吗？');" runat="server" CausesValidation="False" CommandName="Delete" Text="删除"></asp:LinkButton>
                    </ItemTemplate>
                </asp:TemplateField>
               <asp:TemplateField>
                    <ItemTemplate>
                        <input type="button" class="btnup" value="升序" />
                        <input type="button" class="btndown" value="降序" />
                    </ItemTemplate>
                </asp:TemplateField>
                <asp:BoundField DataField="px" HeaderText="排序值" SortExpression="px" />
            </Columns>
        </asp:GridView>
        <asp:AccessDataSource ID="accessdata" runat="server" 
            DataFile="~/App_Data/db.mdb" 
            DeleteCommand="DELETE FROM [Sys_Dictionary] WHERE [ID] = ?"            
            SelectCommand="SELECT * FROM [Sys_Dictionary] where pid=?  ORDER BY [px], [addtime]  " 
            UpdateCommand="UPDATE [Sys_Dictionary] SET [pid] = ?, [keytext] = ?, [keyvalue] = ?, [px] = ?, [updatetime] =now(), [remark] = ? WHERE [ID] = ?">
             <SelectParameters>
            <asp:QueryStringParameter QueryStringField="pid" DefaultValue="0" Name="pid" Type="Int32" />
        </SelectParameters>
            <DeleteParameters>
                <asp:Parameter Name="ID" Type="Int32" />
            </DeleteParameters>
            <UpdateParameters>
                <asp:Parameter Name="pid" Type="Int32" />
                <asp:Parameter Name="keytext" Type="String" />
                <asp:Parameter Name="keyvalue" Type="String" />
                <asp:Parameter Name="px" Type="Int32" />             
                <asp:Parameter Name="remark" Type="String" />
                <asp:Parameter Name="ID" Type="Int32" />
            </UpdateParameters>       
        </asp:AccessDataSource>
    </div>
    <asp:SqlDataSource ID="sqserverlData" runat="server" ConnectionString="<%$ ConnectionStrings:strWeb %>" SelectCommand="SELECT * FROM [Sys_Dictionary] where pid=@pid  ORDER BY [px], [addtime]  " DeleteCommand="DELETE FROM [Sys_Dictionary] WHERE [id] = @id" UpdateCommand="UPDATE [Sys_Dictionary] SET [pid] = @pid, [keytext] = @keytext, [keyvalue] = @keyvalue, [px] = @px,[remark] = @remark,updatetime=getdate()  WHERE [id] = @id">
        <DeleteParameters>
            <asp:Parameter Name="id" Type="Int32" />
        </DeleteParameters>
        <SelectParameters>
            <asp:QueryStringParameter QueryStringField="pid" DefaultValue="0" Name="pid" Type="Int32" />
        </SelectParameters>
        <UpdateParameters>
            <asp:Parameter Name="pid" Type="Int32" />
            <asp:Parameter Name="keytext" Type="String" />
            <asp:Parameter Name="keyvalue" Type="String" />
            <asp:Parameter Name="px" Type="Int32" />
            <asp:Parameter Name="remark" Type="String" />
            <asp:Parameter Name="id" Type="Int32" />
        </UpdateParameters>
    </asp:SqlDataSource>
</asp:Content>
